# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from .sql import Sql


# class AmazonPipeline(object):
#     def process_item(self, item, spider):
#         if not Sql.is_repeat(item["goods_name"],item["goods_price"]):
#             Sql.insert_table_goods(item["goods_name"],item["goods_price"])
#         print(item["goods_name"])
#         print(item["goods_price"])

class BlogyuanPipeline(object):
    def process_item(self, item, spider):
        if not Sql.is_repeat("article", url=item["url"]):
            print("未重复", item["title"])
            try:
                Sql.insert("article", title=item["title"], url=item["url"], creat_time=item["creat_time"],
                           content=item["text"])
            except Exception as e:
                print("error:",str(e))
                Sql.insert("article", title=item["title"], url=item["url"], creat_time=item["creat_time"],
                           content=str(e))
        else:
            print("重  复", item["title"])
            # print(item["url"])
            # print(item["creat_time"])
            # print(item["text"])
